package com.kotlin.heimaplayer.presenter.impl

import com.kotlin.heimaplayer.base.BaseListPresenter
import com.kotlin.heimaplayer.base.BaseView
import com.kotlin.heimaplayer.model.CommonResultBean
import com.kotlin.heimaplayer.model.HomeItemBean
import com.kotlin.heimaplayer.net.HomeRequest
import com.kotlin.heimaplayer.net.ResponseHandler
import com.kotlin.heimaplayer.presenter.interf.HomePresenter
import com.kotlin.heimaplayer.view.HomeView

class HomePresenterImpl(var homeView: BaseView<List<HomeItemBean>>?) : HomePresenter,
    ResponseHandler<CommonResultBean<List<HomeItemBean>>> {
    override fun destoryView() {
        if(homeView != null){
            homeView = null
        }
    }

    override fun onError(type:Int,msg: String?) {
        homeView?.onError(msg)
    }

    override fun onSuccess(type:Int,result: CommonResultBean<List<HomeItemBean>>) {
        println("首页加载"+type)
        when(type){
            BaseListPresenter.TYPE_INIT_OR_REFRESH->homeView?.loadSuccess(result.data)
            BaseListPresenter.TYPE_LOAD_MORE->homeView?.loadMore(result.data)
        }
    }

    override fun loadMore(page: Int) {

        HomeRequest(BaseListPresenter.TYPE_LOAD_MORE,page,this).excute()


    }

    override fun loadDatas() {
        HomeRequest(BaseListPresenter.TYPE_INIT_OR_REFRESH,1,this).excute()
    }

}